#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
// 感觉思路有点麻烦， 学习一下算法笔记上的写法
const int N = 1e5 + 10;
int n;
int man1[3];
int man2[3];
int p1[3];
int p2[3];
int main()
{
    char mp[3] = {'B', 'C', 'J'};
    scanf("%d", &n);
    while(n --)
    {
        char c1, c2;
        cin >> c1 >> c2;
        if(c1 == c2) man1[1] ++, man2[1] ++;
        else if((c1 == 'C' && c2 == 'J') || (c1 == 'J' && c2 == 'B') || (c1 == 'B' && c2 == 'C')){
            man1[0] ++, man2[2] ++;
            if(c1 == 'B') p1[0] ++;
            if(c1 == 'C') p1[1] ++;
            if(c1 == 'J') p1[2] ++;
        } else {
            man1[2] ++, man2[0] ++;
            if(c2 == 'B') p2[0] ++;
            if(c2 == 'C') p2[1] ++;
            if(c2 == 'J') p2[2] ++;
        }
    }
    
    printf("%d %d %d\n", man1[0], man1[1], man1[2]);
    printf("%d %d %d\n", man2[0], man2[1], man2[2]);
    int res1 = 0, res2 = 0;
    int temp1 = p1[0], temp2 = p2[0];
    for(int i = 1; i < 3; i ++)
    {
        if(temp1 < p1[i]) temp1 = p1[i], res1 = i;
        if(temp2 < p2[i]) temp2 = p2[i], res2 = i;
    }
    printf("%c %c", mp[res1], mp[res2]);
    return 0;
}

